package com.swhysc.information.common.model;

import java.util.Map;

/**
 * @Author zmq
 * @Date 2023/8/30 17:13
 * @Description
 */
public class PageAble {
    private Integer page;
    private Integer pageSize;
    private static final Integer PAGE_DEFAULT = 1;
    private static final Integer PAGE_SIZE_MAX = 2147483647;

    private PageAble(Integer page, Integer pageSize) {
        this.page = page;
        this.pageSize = pageSize;
    }

    public static PageAble createPage(Integer page, Integer pageSize) {
        page = page == null ? PAGE_DEFAULT : page;
        pageSize = pageSize == null ? PAGE_SIZE_MAX : pageSize;
        return new PageAble(page, pageSize);
    }

    public static PageAble createPage(Object page, Object pageSize) {
        Integer pageNum;
        try {
            pageNum = (Integer)page;
        } catch (Exception var6) {
            pageNum = PAGE_DEFAULT;
        }

        Integer sizeNum;
        try {
            sizeNum = (Integer)pageSize;
        } catch (Exception var5) {
            sizeNum = PAGE_SIZE_MAX;
        }

        return new PageAble(pageNum, sizeNum);
    }

    public static PageAble createPage(Map param) {
        Integer pageNum;
        try {
            pageNum = Integer.parseInt((String)param.get("page"));
        } catch (Exception var5) {
            pageNum = PAGE_DEFAULT;
        }

        param.remove("page");

        Integer sizeNum;
        try {
            sizeNum = Integer.parseInt((String)param.get("rows"));
        } catch (Exception var4) {
            sizeNum = PAGE_SIZE_MAX;
        }

        param.remove("rows");
        return new PageAble(pageNum, sizeNum);
    }

    public Integer getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPage() {
        return this.page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getOffset() {
        return (this.getPage() - 1) * this.getPageSize();
    }
}
